People drink coffee for various reasons: Either to warm their soul in a chilling morning, or to stay awake and focus after a long, restless night. Whatever the reason is, it is clear that we love the dark, fragrance liquid. Some people loves coffee for its pleasant aroma. Some others loves its unique flavor notes. Some simply loves it because it is as black as their soul. But most would agree that nothing is better than a cup of great coffee to start a wonderful, productive day.
Great coffee beans produce great coffee cup. The question is, what do we, coffee lovers, should consider when planning to buy a premium bag of the charming black beans? Hence, in this report. We will have a journey to the place where the coffee trees were raised and the beans were harvested, to see what affects the quality of our beloved coffee.
The Coffee Quality Institute is a non-profit organization that grades coffee samples from around the world in a consistent and professional manner.
The coffee beans are graded by the CoffeeQuality (2020)’s trained reviewers. The total rating of a coffee bean is a cumulative sum of 10 individual quality measures: aroma, flavour, aftertaste, acidity, body, balance, uniformity, clean cup, sweetness and cupper points. Each grade is on a 0–10 scale resulting to a total cupping score between zero and one hundred.
The data is originally observed from Coffee Quality Institute website and was scraped by DeLoux (2018), the data was then re-posted on Kaggle. Furthermore, Mock (2020) did the initial cleaning for the scraped data.
The cleaned data set consists of 1339 observations and 43 variables. Some potential limitations are identified:
As the number of graded coffee beans differ largely from country to country, some of the analysis will be biased.
For US, there are 3 areas that produce coffee beans: Mainland, Puerto Rico and Hawaii. In this research, the researchers merge all this areas together to better represent the country.
There are outliers in data, which may require further cleaning before certain analysis can take place.
There are difference in scale system in the data. In detail, it is unclear whether the altitude of a farm was converted from meter to feet.
Data wrangling and cleaning is crucial to produce an exploratory data analysis fluently. The original data is a data frame scraped by James LeDoux in January 2018 from the Coffee Quality Institute website which has a few missing values columns within it, so the author has cleaned the data set by removing the variables: “view_certificate_1”, “view_certificate_2”,etc. On the other hand, there are two separate data set raw_robusta and raw_arabica originally. Thomas Mock first cleaned the variable names in both data set with function janitor::clean_names, and inappropriate data class is corrected using col_double, col_character etc. Variables like salt_acid, bitter_sweet, fragrance_aroma, mouthfeel, and uniform_cup is renamed to acidity, sweetness, aroma, body and uniformity respectively, to allow a better understanding for readers.
The data sets were then joined by implementing the function bind_rows to produce the merged data set, which is exported to a single csv file “coffee_ratings.csv” with 1339 observations and 43 variables.
Although the dataset was properly cleaned and wrangled by the original author, there are still some issues in the dataset:
There are anomalies in the data. In detail, there are some coffee beans were grown at the height of more than 11,000 meters. Given that the highest point on Earth is only 8,848 meters above sea level, those observations are inaccurate.
There are several missing values in the dataset. In order to be more accurate at our research, we tried to fill some critical information that can affect our data.
Based on this, the data set was cleaned again to produce the most accurate analysis possible.
After the cleaning procedure, knowing what each of those variables define with respect to our topic is important so below is the description of variables included in the data set:
| Variable | Class | Description |
|---|---|---|
| total_cup_points | double | Total rating/points (0 - 100 scale) |
| species | character | Species of coffee bean (arabica or robusta) |
| owner | character | Owner of the farm |
| country_of_origin | character | Where the bean came from |
| farm_name | character | Name of the farm |
| lot_number | character | Lot number of the beans tested |
| mill | character | Mill where the beans were processed |
| ico_number | character | International Coffee Organization number |
| company | character | Company name |
| altitude | character | Altitude - this is a messy column - I’ve left it for some cleaning |
| region | character | Region where bean came from |
| producer | character | Producer of the roasted bean |
| number_of_bags | double | Number of bags tested |
| bag_weight | character | Bag weight tested |
| in_country_partner | character | Partner for the country |
| harvest_year | character | When the beans were harvested (year) |
| grading_date | character | When the beans were graded |
| owner_1 | character | Who owns the beans |
| variety | character | Variety of the beans |
| processing_method | character | Method for processing |
| aroma | double | Has both fragrance (ground beans) and aroma (hot water with coffee powder) |
| flavor | double | Flavor grade |
| aftertaste | double | Length of positive flavor remaining after the coffee is swallowed |
| acidity | double | The score depends on the origin characteristics and other factors(degree of roast) |
| body | double | Body grade |
| balance | double | Balance grade |
| uniformity | double | Refers to the consistency of flavor . 2 points are awarded for each cup displaying this attribute, with a maximum of 10 points if all 5 cups are the same. |
| clean_cup | double | Refers to a lack of interfering negative impressions from first ingestion to final aftertaste |
| sweetness | double | Sweetness grade |
| cupper_points | double | The cupper marks the intensity of the Aroma on a scale |
| moisture | double | Moisture Grade |
| category_one_defects | double | Full black or sour bean, pod/cherry, and large or medium sticks or stones(count) |
| quakers | double | Unripened beans that are hard to identify during hand sorting and green bean inspection |
| color | character | Color of bean |
| category_two_defects | double | Parchment, hull/husk, broken/chipped, insect damage, partial black or sour, shell, small sticks or stones, water damage(count) |
| expiration | character | Expiration date of the beans |
| certification_body | character | Who certified it |
| certification_address | character | Certification body address |
| certification_contact | character | Certification contact |
| unit_of_measurement | character | Unit of measurement |
| altitude_low_meters | double | Altitude low meters |
| altitude_high_meters | double | Altitude high meters |
| altitude_mean_meters | double | Altitude mean meters |
The aim of this report is to discover the likely factors that influence coffee quality and taste.
Secondary question:
Which Country produces the best quality coffee beans? Are there any large difference in coffee quality worldwide?
Do factors like altitude and defects affect the quality of the coffee?
Are coffee graders consistent with their grading across years, months and days of the week? (NEW)
What is the common processing method of top-graded coffee beans, how different processing method behaves on the individual grading criteria of coffee? (NEW)
Figure 3.1 aims to address the primary question Which country produces best quality coffee beans?. X axis shows the overall rating achieved by the coffee bean while Y axis denotes the country where it produced.
It is clear that Ethiopia produced the highest quality of coffee beans. However, it is interesting to note that there is not much variation between countries as most of them have median score of around 80-85 points. Thus, We can conclude based on the dataset, that there is not much difference in coffee quality between countries, with Ethipoia produces the highest-quality beans.
Figure 3.1: Boxplot for total ratings of coffee beans of country with at least 5 coffee samples.
The dataset contains information about the coffee sample’s altitude of origin, variety, processing method and color. In this section, I’ll examine whether any of these characteristics correlate with the total cupping score.
In this section, our team ran a model for the altitude of the sample and its total cupping score. The result is displayed in table 3.1 and figure 3.2. The p-value is lower then 0.05 which indicates that the model is statistically significant. The result shows a positive relationship between altitude and quality of coffee beans produced. However, it is worth to notice that the Adjusted R Square of the model is extremely small, only 0.022, or 2% (See table 5.1, Appendix 1), suggesting an extremely weak model, that only 2% of the variation is explained. Therefore, I tried another method which is Pearson correlation coefficient to examine the relationship between altitude and cupping points. As suggested by table 3.2, there are no significant correlation.
There are some very interesting findings from 3.2. For example, it seems that the majority of coffee samples were grown 750-2000m above sea levels. Also, most of coffee beans seems to score very high, around 80-85 points.
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 81.09426 | 0.22743 | 356.56384 | 0 |
| altitude_mean_meters | 0.00082 | 0.00016 | 5.11726 | 0 |
Figure 3.2: Altitude and Total cup points dot plot, blueline presents fitted regression model, redlines indicate present altitude of 750m and 2000m.
| estimate | statistic | p.value | parameter | conf.low | conf.high | method | alternative |
|---|---|---|---|---|---|---|---|
| -0.0201263 | -0.6694689 | 0.5033361 | 1106 | -0.0789258 | 0.0388127 | Pearson’s product-moment correlation | two.sided |
After the linear model for altitude turned out to be insignificant, we figured there are several other variables in the dataset that we could try fitting a model. The dataset contains category one and category two defects which are also known as primary and secondary defects and we fitted a muti-variate model using the same. The model after considering both the variables return a p-value very close to 0 and hence this model is considered as significant and in Figure 1 suggesting that almost all the residuals reside very close to the 0 line with a very few outliers. Overall, we conclude that defects influence the quality of coffee beans produced.
However, what’s the extent of the influence? Both R.squared (5.06%) and adjusted R squared (4.92%) tells that defects have minimal influence on the quality of coffee beans, that only 5% of variations in total cup points is explained by category one and category two defects.
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 82.5885115 | 0.1122747 | 735.593003 | 0.00000 |
| category_one_defects | -0.1106967 | 0.0378995 | -2.920796 | 0.00355 |
| category_two_defects | -0.1252918 | 0.0181894 | -6.888192 | 0.00000 |
Figure 3.3: Relationship between defects and quality
| r.squared | adj.r.squared | sigma | statistic | p.value | df | logLik | AIC | BIC | deviance | df.residual | nobs |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0.050619 | 0.0491978 | 3.413379 | 35.61635 | 0 | 2 | -3542.351 | 7092.702 | 7113.501 | 15565.95 | 1336 | 1339 |
While waiting for my lovely cup of coffee to brew, one of the researcher happened to read a interesting research Danziger, Levav, and Avnaim-Pesso (2011) that has found correlation between a parole case’s success rate and whether the case was heard right before or after lunch. The idea is that judges might be more exhausted before lunch, which would make them stricter. Enlightened, he wanted to see if there is anything similar happen in coffee grading. Are graders stricter on Friday compared to Monday?
Figure 3.4: Mean total cup scores by week day. The average point stay stable throughout the week
The answer seems to be No.
From figure 3.4, it seems that coffee graders seem to be consistent with their grading across the weeks.
But, does this trend stay true across years and months? Figure 3.5 answer that question. The figure suggest that the score remain stable throughout months and years.
From the previous findings, the researchers conclude that coffee graders seem to be consistent with their grading across years, months and days of the week. On that ground, it is safe to say that coffee seems to be consistent in quality throughout the years.
Figure 3.5: Mean total cup score per grading year and month
Processing Method among top-graded coffee beans
Figure 3.6: Common processing method of top 30 coffee beans by country
| Processing Method | Frequency |
|---|---|
| Natural / Dry | 11 |
| Pulped natural / honey | 1 |
| Semi-washed / Semi-pulped | 1 |
| Washed / Wet | 17 |
The bar chart 3.6 demonstrates the frequency of processing method in top 30 coffee bean producers, we discovered that the producers in most countries is using washed/wet method to produce coffee beans, followed by natural/dry method. In addition, majority of coffee bean producers in Ethiopia, the country that produces highest quality coffee beans, is using the natural/dry method. This is explained by Korhonen (2020), “The natural process is common in regions where there is no access to water such as Ethiopia and some regions in Brazil.”
Behavior of different processing method on the individual grading criteria of coffee
We picked 6 grading criteria, according to the coffee scoring article provided on (“Scoring Coffee” 2020):
Figure 3.7: Scatterplot matrix of grading criterias, differentiated by processing method
The scatterplot matrix 3.7 examines the relationship between each grading criteria, and is differentiated by the processing method.
The scatterplot matrix demonstrates the correlation of grading criterias are positive to various extent.
The density plot for acidity indicates the method “Pulped natural/honey” have relatively low density compared to other processing methods.
One thing to notify is that there are presence of outliers for “Washed/Wet” method for every column that relates to aroma grade.
A bunch of coffee beans processed with “Washed/Wet” method have relatively lower aftertaste grade.
Overall, we can observe that the “Washed/Wet” method have relatively more variations compared to other method, and the plot 3.7 also indicates the primary processing method are “Washed/Wet” and “Natural/Dry” across all coffee bean producers. And we can barely capture the appearance of other two methods.
In this section, we provide radar charts of five countries from across the world: Ethiopia, United States, Brazil, Peru and Indonesia. A radar chart is a useful way to depict multi-variate observations. Each criteria is rated out of a total 10 points and all the 10 criteria are plotted together on the radar chart along with moisture percentage to understand how a particular country performs on individual criteria.
| country | ma | mfl | maf | mac | mb | mba | mu | mc | ms | mcu | mm |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Brazil | 7.553106 | 7.573561 | 7.440530 | 7.511439 | 7.544545 | 7.531515 | 9.884924 | 9.853485 | 9.949394 | 7.562955 | 0.0823485 |
| Ethiopia | 7.896364 | 8.009091 | 7.893864 | 8.043636 | 7.924091 | 7.972273 | 9.878409 | 9.954318 | 9.863409 | 8.048636 | 0.0829545 |
| Indonesia | 7.649000 | 7.573000 | 7.415500 | 7.491000 | 7.631500 | 7.520000 | 9.933000 | 9.966500 | 9.966500 | 7.416500 | 0.0985000 |
| Peru | 7.693000 | 7.658000 | 7.541000 | 7.699000 | 7.802000 | 7.666000 | 9.533000 | 9.466000 | 9.866000 | 7.601000 | 0.0660000 |
| US | 7.605977 | 7.622529 | 7.541609 | 7.651609 | 7.652414 | 7.664138 | 9.501379 | 9.608966 | 9.643218 | 7.623448 | 0.0509195 |
After looking at these plots, the conclusion drawn are as follows: The common characteristics that these top 5 countries have are the consistent higher values of uniformity and clean cup. Among all these countries, it can be seen that the country Ethiopia has the highest values for all the different characteristics that we have proven to have a significant affect on the quality of the coffee beans in the above sections. It is also interesting how the sweetness has a perfect score of 10 in all other countries other than United States as depicted.
After a series of analysis on quality of coffee beans and coffee grading, we can now come up with suggestions for coffee lovers when planning to buy a premium bag of coffee beans. Surprisingly, from the data provided, factors like altitude and defects, had almost no influence on the quality of coffee bean (which contradicts to what we expected before the analysis). Good news is that, after a long development of coffee production, coffee quality seems to score very high,around 80-85 points across the world.
In conclusion, neither country of origin, nor altitude, nor defects really have large impact on the quality of coffee beans. So, if you want to buy a bag of coffee, you should keep that in mind and instead choose the coffee that best suited your taste. A little tip here, if you’re looking for fermented and wild flavors in the cup, coffee bean from Ethiopia (processed with Natural/Dry method) will surely satisfy you.
| r.squared | adj.r.squared | sigma | statistic | p.value | df | logLik | AIC | BIC | deviance | df.residual | nobs |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0.023211 | 0.0223247 | 2.599242 | 26.18637 | 4e-07 | 1 | -2620.07 | 5246.14 | 5261.16 | 7445.176 | 1102 | 1104 |
R packages used:
CoffeeQuality, Institute. 2020. “Grade Details, Q Arabica Q Arabica Certificate.” Coffee Quality Institute. https://database.coffeeinstitute.org/coffee/357789/grade.
Danziger, Shai, Jonathan Levav, and Liora Avnaim-Pesso. 2011. “Extraneous Factors in Judicial Decisions,” April. https://doi.org/doi: 10.1073/pnas.1018033108.
DeLoux, James. 2018. “Coffee Quality Database.” GitHub Repository. https://github.com/jldbc/coffee-quality-database.
Grolemund, Garrett, and Hadley Wickham. 2011. “Dates and Times Made Easy with lubridate.” Journal of Statistical Software 40 (3): 1–25. http://www.jstatsoft.org/v40/i03/.
Korhonen, Jori. 2020. “Coffee Processing Methods – Drying, Washing or Honey?” Barista Institute. https://www.baristainstitute.com/blog/jori-korhonen/january-2020/coffee-processing-methods-drying-washing-or-honey.
Mock, Thomas. 2020. “R for Data Science.” GitHub Repository. https://github.com/rfordatascience/tidytuesday/blob/master/data/2020/2020-07-07/readme.md.
Schloerke, Barret, Di Cook, Joseph Larmarange, Francois Briatte, Moritz Marbach, Edwin Thoen, Amos Elberg, and Jason Crowley. 2020. GGally: Extension to ’Ggplot2’. https://CRAN.R-project.org/package=GGally.
“Scoring Coffee.” 2020. My Cuppa. https://www.mycuppa.com.au/scoring-coffee.
Sievert, Carson. 2020. Interactive Web-Based Data Visualization with R, Plotly, and Shiny. Chapman; Hall/CRC. https://plotly-r.com.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.
Zhu, Hao. 2019. KableExtra: Construct Complex Table with ’Kable’ and Pipe Syntax. https://CRAN.R-project.org/package=kableExtra.